/**
*      author: Y_Yao
*      created: 2024-11-25 16:11:17
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 1e18;
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 7;
int sum1[N],sum2[N];
int n,Q;
int L,R;
string s;
vector<int> c;

int get_cnt1(int l,int r)
{
    return sum1[r] - sum1[l-1];
}

int get_cnt2(int l,int r)
{
    return sum2[r] - sum2[l-1];
}

int get_ans(int c_pos)
{
    if(c[c_pos] < L || c[c_pos] > R)
    {
        return 0;
    }
    int cnt1 = get_cnt1(L,c[c_pos] - 1);
    int cnt2 = get_cnt2(c[c_pos] + 1,R);
    return min(cnt1,cnt2) * 2 + 1;
}

void solve()
{
    cin >> n >> Q;
    cin >> s;
    s = " " + s;
    for(int i = 1;i <= n;i++)
    {
        sum1[i] = s[i] == '1' ? sum1[i-1] + 1 : sum1[i-1]; 
        sum2[i] = s[i] == '2' ? sum2[i-1] + 1 : sum2[i-1];
        if(s[i] == '/') c.push_back(i); 
    }

    while(Q--)
    {
        cin >> L >> R;
        int l = 0,r = c.size() - 1;
        int ans_pos = n + 1;
        if(c.size() == 0)
        {
            cout << 0 << endl;
            continue;
        }
        while(l <= r)
        {
            int mid = (l + r) >> 1;
            int pos = c[mid];
            if(pos < L)
            {
                l = mid + 1;
                continue;
            }
            else if(pos > R)
            {
                r = mid - 1;
                continue;
            }
            int cnt1 = get_cnt1(L,pos - 1);
            int cnt2 = get_cnt2(pos + 1,R);
            if(cnt1 >= cnt2)
            {
                ans_pos = min(ans_pos,mid);
                r = mid - 1;
            }
            else
            {
                l = mid + 1;
            }
        }

        if(ans_pos == n + 1)//没找到
        {
            auto it = lower_bound(c.begin(),c.end(),R + 1);
            if(it == c.end())
            {
                ans_pos = c.size() - 1;
            }
            else ans_pos = it - c.begin();
        }

        int ans = 0;
        ans = max(get_ans(ans_pos),ans_pos == 0 ? 0 : get_ans(ans_pos - 1));
        cout << ans << endl;
    }

}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}